﻿using HotelManager.Models;
using HotelManager.Models.Params;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HotelManager.Service
{
    public class GuestService:IGuestService
    {
        private readonly HttpRestClient client;
        public GuestService(HttpRestClient client)
        {
            this.client = client;
        }



        public ResultData<string> Delete(GuestDetailData guestDetailData)
        {
            BaseRequest request = new BaseRequest();
            GuestDeleteParam guestDeleteParam = new GuestDeleteParam() {guestId=guestDetailData.guestId };
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/GuestRecord/Delete";
            request.Parameter = guestDeleteParam;
            return client.ExecuteSync<ResultData<string>>(request);
        }

        public GuestDetailInfoData GetAll(string guestName, int resideStateId, int pageIndex, int pageSize)
        {
            BaseRequest request = new BaseRequest();
            GuestListRecordParam guestListRecordParam=new GuestListRecordParam() { guestName= guestName, resideStateId= resideStateId, pageIndex=pageIndex, pageSize=pageSize};
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/GuestRecord/List";
            request.Parameter = guestListRecordParam;
            return client.ExecuteSync<GuestDetailInfoData>(request);
        }

        public GuestReturnOneData GetFirstOrDefaultAsync(int guestId)
        {
            BaseRequest request = new BaseRequest();
            request.Method = RestSharp.Method.Get;
            request.Route = $"api/GuestRecord/GetOne?guestId={guestId}";
            return client.ExecuteGetSync<GuestReturnOneData>(request);
        }
        public ResultData<string> Add(GuestReturnOneData guestReturnOneData)
        {
            BaseRequest request = new BaseRequest();
            GuestDataAddParam guestDataAddParam = new GuestDataAddParam()
            {
                guestId = guestReturnOneData.guestId,
                guestName = guestReturnOneData.guestName,
                identityId = guestReturnOneData.identityId,
                phone = guestReturnOneData.phone,
                roomId = guestReturnOneData.roomId,
                resideDate = DateTime.Parse(guestReturnOneData.resideDate),
                deposit = guestReturnOneData.deposit,
                guestNum = guestReturnOneData.guestNum,
                roomTypeId = guestReturnOneData.room.RoomTypeId,
            };
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/GuestRecord/Add";
            request.Parameter = guestDataAddParam;
            return client.ExecuteSync<ResultData<string>>(request);
        }
        public ResultData<string> Update(GuestReturnOneData guestReturnOneData)
        {
            BaseRequest request = new BaseRequest();
            GuestDataAddParam guestDataAddParam = new GuestDataAddParam() 
            {
                guestId = guestReturnOneData.guestId,
                guestName = guestReturnOneData.guestName,
                identityId = guestReturnOneData.identityId,
                phone = guestReturnOneData.phone,
                roomId = guestReturnOneData.roomId,
                resideDate = DateTime.Parse(guestReturnOneData.resideDate),
                deposit = guestReturnOneData.deposit,
                guestNum = guestReturnOneData.guestNum,
                roomTypeId = guestReturnOneData.room.RoomTypeId,
            };
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/GuestRecord/Update";
            request.Parameter = guestDataAddParam;
            return client.ExecuteSync<ResultData<string>>(request);
        }

        public GuestData CheckOut(GuestDetailData guestDetailData)
        {
            BaseRequest request = new BaseRequest();
            CheckoutParam guestDeleteParam = new CheckoutParam() { guestId = guestDetailData.guestId };
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/GuestRecord/Checkout";
            request.Parameter = guestDeleteParam;
            return client.ExecuteSync<GuestData>(request);
        }
    }
}
